<?php
	include_once "dataservice.php";
	
	class chuyenmuc_db
	{
		public function Them($MaChuDe, $TenChuyenMuc, $MaTrangThai, $PIN)
		{
			$sql = "INSERT INTO `tbl_chuyenmuc`(`MaChuDe`, `TenChuyenMuc`, `MaTrangThai`, `PIN`) 
					VALUES ('$MaChuDe', '$TenChuyenMuc', '$MaTrangThai', '$PIN')";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function CapNhat($MaChuyenMuc, $MaChuDe, $TenChuyenMuc, $MaTrangThai, $PIN)
		{
			$sql = "UPDATE 	`tbl_chuyenmuc` 
					SET 	`MaChuDe`      = '$MaChuDe',
							`TenChuyenMuc` = '$TenChuyenMuc',
							`MaTrangThai`  = '$MaTrangThai',
							`PIN`          = '$PIN'
					WHERE 	`MaChuyenMuc`='$MaChuyenMuc'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function CapNhatMaTrangThai($MaChuyenMuc, $MaTrangThai)
		{
			$sql = "UPDATE 	`tbl_chuyenmuc` 
					SET 	`MaTrangThai` = '$MaTrangThai'
					WHERE 	`MaChuyenMuc` = '$MaChuyenMuc'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		public function Xoa($MaChuyenMuc)
		{
			$sql = "DELETE FROM `tbl_chuyenmuc` WHERE `MaChuyenMuc` = '$MaChuyenMuc'";
			
			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}
		
		public function LayDanhSach($MaChuyenMuc, $MaChuDe, $MaTrangThai)
		{
			$sql = "SELECT * FROM `tbl_chuyenmuc` WHERE 1";
			
			if($MaChuyenMuc != 0)
				$sql .= " AND `MaChuyenMuc` = $MaChuyenMuc";
			if($MaChuDe != 0)
				$sql .= " AND `MaChuDe` = $MaChuDe";
			if($MaTrangThai != -1)
				$sql .= " AND `MaTrangThai` = $MaTrangThai";
			
			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}
		
		public function LayTenChuyenMuc($MaChuyenMuc)
		{
			$sql = "SELECT `TenChuyenMuc` FROM `tbl_chuyenmuc` WHERE `MaChuyenMuc`='$MaChuyenMuc'";
			
			$service = new dataservice();
			return $service->ExecuteScalar($sql);
		}
	}
?>